package com.cd.university.common.utils;

import com.cd.university.common.UniversityConstants;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.util.AlternativeJdkIdGenerator;
import org.springframework.util.IdGenerator;

import java.util.Locale;

/**
 * 编号生成类，全局唯一，单列类
 * @author 陈栋
 * @create 2021/10/13 14:12
 */
public class MyIdGenerator {


    private MyIdGenerator() {
    }

    private static class SingletonHolder {
        private static final MyIdGenerator instance = new MyIdGenerator();
    }

    public static MyIdGenerator getInstance() {
        return SingletonHolder.instance;
    }

    public String getRandomNumber() {
        // 使用Spring框架的UUID生成器
        AlternativeJdkIdGenerator idGenerator = new AlternativeJdkIdGenerator();
        System.out.println("生成的唯一id："+idGenerator.generateId());

        return idGenerator.generateId().toString().replace("-","").toUpperCase(Locale.ROOT);
    }
}
